package com.example.aishop.service;

import com.example.aishop.entity.Product;
import com.example.aishop.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {
    
    @Autowired
    private ProductMapper productMapper;
    
    // 创建产品
    public boolean save(Product product) {
        return productMapper.insert(product) > 0;
    }
    
    // 根据ID查询产品
    public Product findById(Long id) {
        return productMapper.selectOneById(id);
    }
    
    // 查询所有产品
    public List<Product> findAll() {
        return productMapper.selectAll();
    }
    
    // 更新产品
    public boolean update(Product product) {
        return productMapper.update(product) > 0;
    }
    
    // 删除产品
    public boolean deleteById(Long id) {
        return productMapper.deleteById(id) > 0;
    }
}